import { ICompatibleAdapter, AdapterInfo, ProtocolType } from '../core/interfaces';

export class DnsAdapter implements ICompatibleAdapter {
    getInfo(): AdapterInfo {
        return {
            name: 'DnsAdapter',
            version: '1.0.0',
            target: 'dns',
            protocol: ProtocolType.DNS,
            description: 'DNS protocol adapter with caching support'
        };
    }

    isSupported(): boolean {
        // 总是支持DNS协议
        return true;
    }

    supportsProtocol(protocol: ProtocolType): boolean {
        return protocol === ProtocolType.DNS;
    }

    async execute<T>(input: T): Promise<T> {
        // DNS适配器不执行通用操作
        return input;
    }

    async resolve(hostname: string): Promise<string> {
        // 实现DNS解析逻辑
        // 这里只是模拟，实际实现可以使用dns模块
        if (hostname === 'localhost') {
            return '127.0.0.1';
        }
        return `192.168.1.1 (resolved by DnsAdapter)`;
    }
}